package com.orangelife.mobile.login.adapter;

import java.util.List;
import java.util.Map;

import com.curry.orangelife.mobile.R;
import com.curry.android.adapter.FatherAdapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

@SuppressWarnings("hiding")
public class SelectCityGridAdapter<T> extends FatherAdapter<T> {

	private Context mContext;
	private LayoutInflater listContainer;
	private List<Map<String,Object>> list;
	public final class ListItemView {
		public TextView tv_item_name;
	}

	public SelectCityGridAdapter(Context context, List<Map<String,Object>> list) {
		this.mContext = context;
		listContainer = LayoutInflater.from(mContext);
		this.list = list;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@SuppressWarnings("unchecked")
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ListItemView listItemView = null;
		
		if(convertView == null) {
			listItemView = new ListItemView();
			convertView = listContainer.inflate(R.layout.item_gv_select_city, null);
			
			listItemView.tv_item_name = (TextView)convertView.findViewById(R.id.tv_city);
			
			convertView.setTag(listItemView);
		} else {
			listItemView = (ListItemView)convertView.getTag();
		}
		for (int i = 0; i < list.size(); i++) {
			String city =list.get(position).get("city").toString();
			if(city.equals("null")){
				city="";
			}
			listItemView.tv_item_name.setText(city);
		}
		return convertView;
	}

	@SuppressWarnings("unchecked")
	@Override
	public BaseAdapter setList(List<T> list) {
		this.list=(List<Map<String, Object>>) list;
		return SelectCityGridAdapter.this;
	}

}